home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / sbin_-_Static_Binary_Files / MAKEPKG < prev    next >
Text File  |  1999-09-17  |  6KB  |  167 lines

  1. #!/bin/sh
  2. # Copyright 1994, 1998  Patrick Volkerding, Moorhead, Minnesota USA 
  3. # All rights reserved.
  4. #
  5. # Redistribution and use of this script, with or without modification, is
  6. # permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of this script must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. #
  11. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  14. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  17. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  18. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  19. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  20. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. #
  22. # Wed Mar 18 15:32:33 CST 1998
  23. # Patched to avoid possible symlink attacks in /tmp.
  24.  
  25. make_install_script() {
  26.  COUNT=1
  27.  LINE="`sed -n "$COUNT p" $1`"
  28.  while [ ! "$LINE" = "" ]; do
  29.   LINKGOESIN="`echo "$LINE" | cut -f 1 -d " "`" 
  30.   LINKGOESIN="`dirname $LINKGOESIN`" 
  31.   LINKNAMEIS="`echo "$LINE" | cut -f 1 -d ' '`"
  32.   LINKNAMEIS="`basename "$LINKNAMEIS"`"
  33.   LINKPOINTSTO="`echo "$LINE" | cut -f 3 -d ' '`"
  34.   echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )"
  35.   echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )"
  36.   COUNT=`expr $COUNT + 1`
  37.   LINE="`sed -n "$COUNT p" $1`"
  38.  done
  39. }
  40.  
  41. usage() {
  42.  cat << EOF
  43.  
  44. Usage: makepkg package_name.tgz
  45.  
  46. Makes a Slackware compatible "*.tgz" package containing the contents of the 
  47. current and all subdirectories. If symbolic links exist, they will be removed
  48. and an installation script will be made to recreate them later. This script
  49. will be called "install/doinst.sh". You may add any of your own ash-compatible
  50. shell scripts to this file and rebuild the package if you wish.
  51.  
  52. EOF
  53. }
  54.  
  55. TMP=/tmp # This can be a hole, but I'm going to be careful about file
  56.          # creation in there, so don't panic. :^)
  57.  
  58. # These tests, while by no means exhaustive, will give a usage message
  59. # and exit with a wide range of bad input.
  60.  
  61. if [ ! $# = 1 -a ! $# = 0 ]; then
  62.  usage;
  63.  exit
  64. fi
  65. echo
  66. echo "Slackware package maker, version 1.1."
  67. if [ $# = 0 ]; then
  68.  usage;
  69.  echo "You have not provided a name for this package."
  70.  echo -n "What would you like to call it? "
  71.  read PACKAGE_NAME;
  72. else
  73.  PACKAGE_NAME=$1
  74. fi
  75. TARGET_NAME="`dirname $PACKAGE_NAME`"
  76. PACKAGE_NAME="`basename $PACKAGE_NAME`"
  77. TAR_NAME="`basename $PACKAGE_NAME .tgz`"
  78. echo
  79. echo "Searching for symbolic links:"
  80. # Get rid of possible pre-existing trouble:
  81. rm -rf $TMP/iNsT-a.$$
  82. touch $TMP/iNsT-a.$$
  83. find . -type l -exec ls -l {} \; | cut -b58- | tee $TMP/iNsT-a.$$
  84. if [ ! "`filesize $TMP/iNsT-a.$$`" = "0" ]; then
  85.  echo
  86.  echo "Making symbolic link creation script:"
  87.  make_install_script $TMP/iNsT-a.$$ | tee doinst.sh
  88. fi
  89. echo
  90. if [ ! "`filesize $TMP/iNsT-a.$$`" = "0" ]; then
  91.  if [ -r install/doinst.sh ]; then
  92.   echo "Unless your existing installation script already comtains the code"
  93.   echo "to create these links, you should append these lines to your existing"
  94.   echo "install script. Now's your chance. :^)"
  95.   echo
  96.   echo "Would you like to add this stuff to the existing install script and"
  97.   echo -n "remove the symbolic links ([y]es, [n]o)? "
  98.  else
  99.   echo "It is recommended that you make these lines your new installation script."
  100.   echo
  101.   echo "Would you like to make this stuff the install script for this package"
  102.   echo -n "and remove the symbolic links ([y]es, [n]o)? "
  103.  fi
  104.  read SCRIPTADD;
  105.  if [ "$SCRIPTADD" = "y" ]; then
  106.   if [ -r install/doinst.sh ]; then
  107.    UPDATE="t"
  108.    cat doinst.sh >> install/doinst.sh
  109.   else
  110.    mkdir install
  111.    cat doinst.sh > install/doinst.sh
  112.   fi
  113.   echo
  114.   echo "Removing symbolic links:"
  115.   find . -type l -exec rm -v {} \;
  116.   echo
  117.   if [ "$UPDATE" = "t" ]; then
  118.    echo "Updating your ./install/doinst.sh..."
  119.   else
  120.    echo "Creating your new ./install/doinst.sh..."
  121.   fi
  122.  fi
  123. else
  124.  echo "No symbolic links were found, so we won't make an installation script."
  125.  echo "You can make your own later in ./install/doinst.sh and rebuild the"
  126.  echo "package if you like."
  127. fi
  128. rm -f doinst.sh $TMP/iNsT-a.$$
  129. echo
  130. echo "This next step is optional - you can set the directories in your package"
  131. echo "to some sane permissions. If any of the directories in your package have"
  132. echo "special permissions, then DO NOT reset them here!"
  133. echo 
  134. echo "Would you like to reset all directory permissions to 755 (drwxr-xr-x) and"
  135. echo -n "directory ownerships to root.root ([y]es, [n]o)? "
  136. read PERMS;
  137. echo
  138. if [ "$PERMS" = "y" ]; then
  139.  find . -type d -exec chmod -v 755 {} \; 
  140.  find . -type d -exec chown -v root.root {} \;
  141. fi
  142. echo
  143. echo "Creating tar file $TAR_NAME.tar..."
  144. echo
  145. tar -cvf $TAR_NAME.tar .
  146. # Warn of zero-length files:
  147. find . -type f -size 0c | while read file ; do
  148.   echo "WARNING: zero length file $file"
  149. done
  150. find . -type f -name '*.gz' -size 20c | while read file ; do
  151.   echo "WARNING: possible empty gzipped file $file"
  152. done
  153. echo
  154. echo "Gzipping $TAR_NAME.tar..."
  155. gzip -9 $TAR_NAME.tar
  156. echo
  157. echo "Renaming $TAR_NAME.tar.gz to $PACKAGE_NAME..."
  158. mv $TAR_NAME.tar.gz $PACKAGE_NAME
  159. if [ ! "$TARGET_NAME" = "." ]; then
  160.   echo
  161.   echo "Moving $PACKAGE_NAME to $TARGET_NAME..."
  162.   mv $PACKAGE_NAME $TARGET_NAME
  163. fi
  164. echo
  165. echo "Package creation complete."
  166. echo
  167.